﻿using MediatR;
using SheepStorage.API.Application.Command.AreaCommand;
using SheepStorage.API.Application.Command.ProvinceCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.AreaHandlers
{
    public class AreaListCommandHandlers : IRequestHandler<AreaListCommand, Results<List<Area>>>
    {

        private readonly IAreaService _areaService;

        public AreaListCommandHandlers(IAreaService areaService)
        {
            _areaService = areaService;
        }

        /// <summary>
        /// 显示区域
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<List<Area>>> Handle(AreaListCommand request, CancellationToken cancellationToken)
        {
            return Results<List<Area>>.DataResult(await _areaService.GetArea(request.ProvinceId));
        }
    }
}
